// 打开网站后,浏览器执行缓存,然后需要关闭网站,重新打开网站则生效
// service-worker.js发生任何改变则重新缓存
var precacheConfig = [
  '/web-energy-efficiency/dist/index.html',
  '/web-energy-efficiency/dist/logo.png',
  '/web-energy-efficiency/dist/apple-icon-60x60.png',
  '/web-energy-efficiency/dist/manifest.json'
];
var cacheName = 'sw-precache-v3';
self.addEventListener('install', event => {
  event.waitUntil(caches.open(cacheName).then(res => {
    console.log('ok')
    return res.addAll(precacheConfig)
  }))
})
self.addEventListener('fetch', event => {
  var resPromise = caches.open(cacheName).then(cache => cache.match(event.request).then(res => {
    if(res){
      return res
    }
    return fetch(event.request)
  }))
  event.respondWith(resPromise)
});
